﻿// DrawingBoard20220777View.h: CDrawingBoard20220777View 类的接口
//

#pragma once

#include <vector> // 添加vector头文件

class CDrawingBoard20220777View : public CView
{
protected: // 仅从序列化创建
	CDrawingBoard20220777View() noexcept;
	DECLARE_DYNCREATE(CDrawingBoard20220777View)

	// 特性
public:
	CDrawingBoard20220777Doc* GetDocument() const;

	// 操作
public:
	int m_PenSize;
	COLORREF m_PenColor, m_BrushColor;
	CPoint m_PointBegin, m_PointEnd;
	enum class DrawType {
		None, 
		LineSegment, 
		Circle, 
		Rectangle, 
		Ellips, 
		Pencile, 
		Text, 
		Eraser, 
		myLoadImage, 
		Magnify, 
		Spray, 
		ColorPicker,
		RoundedRectangle, // 圆角矩形
		Heart,            // 爱心形
		Star,             // 星形
		Hexagram,             // 星形
		UpArrow,          // 上箭头
		DownArrow,        // 下箭头
		LeftArrow,        // 左箭头
		RightArrow,       // 右箭头
		Cloud,            // 云形
		Wave,             // 波浪线
		WillowLeaf,       // 柳叶形
		Diamond,          // 菱形
		Hexagon,          // 六边形
		Pentagon,         // 五边形
		bomb,          // 炸弹
		Fill
	} m_DrawType;
	int m_TextId;
	CEdit* m_Edit = nullptr;
	CPoint m_TextPos = CPoint(0, 0);


	COLORREF m_FillColor;         // 填充颜色
	int m_FillTolerance;          // 填充容差 (0-255)
	bool m_FillContiguous;        // 是否连续填充

	COLORREF m_BackgroundColor;

	CPoint m_MagnifyCenter = CPoint(0, 0);
	int m_MagnifyWidth = 600;
	int m_MagnifyHeight = 400;
	double m_ZoomFactor = 2.0; // 默认放大倍数
	bool m_IsZooming = true;   // true为放大模式，false为缩小模式
	// 新增成员变量
	CDC m_MemDC; // 用于双缓冲的内存DC
	CBitmap m_MemBitmap; // 内存位图
	bool m_bDrawing; // 标记是否正在绘制
	std::vector<HBITMAP> m_UndoStack; // 撤销栈 (使用HBITMAP)
	int m_SprayRadius; // 喷墨半径
	CFont m_TextFont;  // 添加文本字体成员变量
	COLORREF m_TextColor; // 文本颜色
	int m_TextSize;     // 文本大小（单位：点）
	std::vector<int> m_WillowPressures;
	std::vector<CPoint> m_WillowPoints;

	std::vector<COLORREF> m_BackgroundColorStack;
	// 重写
public:
	virtual void OnDraw(CDC* pDC);  // 重写以绘制该视图
	virtual BOOL PreCreateWindow(CREATESTRUCT& cs);
protected:
	virtual BOOL OnPreparePrinting(CPrintInfo* pInfo);
	virtual void OnBeginPrinting(CDC* pDC, CPrintInfo* pInfo);
	virtual void OnEndPrinting(CDC* pDC, CPrintInfo* pInfo);
	virtual void CDrawingBoard20220777View::SetTextFont(CFont* pFont);
	virtual void CDrawingBoard20220777View::SaveTextToCanvas();
	virtual void CDrawingBoard20220777View::RemoveTextEdit(bool saveText = false);
	BOOL CDrawingBoard20220777View::OnEraseBkgnd(CDC* pDC);
	void CDrawingBoard20220777View::FloodFill(CPoint point);
	bool CDrawingBoard20220777View::IsColorInTolerance(COLORREF color1, COLORREF color2, int tolerance);
	void CDrawingBoard20220777View::SaveFillSettings();
	// 加载油漆桶设置（可选）
	void CDrawingBoard20220777View::LoadFillSettings();
	void CDrawingBoard20220777View::SetFillColor(COLORREF color);
	void CDrawingBoard20220777View::SetFillTolerance(int tolerance);
	void CDrawingBoard20220777View::SetFillContiguous(bool contiguous);
	void CDrawingBoard20220777View::OnFillColor();


	// 实现
public:
	virtual ~CDrawingBoard20220777View();
#ifdef _DEBUG
	virtual void AssertValid() const;
	virtual void Dump(CDumpContext& dc) const;
#endif

protected:

	// 生成的消息映射函数
protected:
	DECLARE_MESSAGE_MAP()
public:
	afx_msg void OnLButtonDown(UINT nFlags, CPoint point);
	afx_msg void OnMouseMove(UINT nFlags, CPoint point);
	afx_msg void OnLButtonUp(UINT nFlags, CPoint point);
	afx_msg void OnLine();
	afx_msg void OnRectangle();
	afx_msg void OnCircle();
	afx_msg void OnEllipse();
	afx_msg void OnSetColor();
	afx_msg void OnSetPenSize();
	virtual BOOL PreTranslateMessage(MSG* pMsg);
	afx_msg void OnSetPencil();
	afx_msg void OnSetEraser();
	afx_msg void OnFileOpen();
	afx_msg void OnText();
	afx_msg void OnMagnify();

	CRect* GetMagnifyRect(CPoint&);
	afx_msg void OnUndo(); // 撤销
	afx_msg void OnReload(); // 重新加载
	afx_msg void OnSpray(); // 喷墨
	afx_msg void OnColorPicker(); // 颜色提取

	CBrush m_BackgroundBrush;    // 背景画刷
	virtual afx_msg void OnSetBackgroundColor();
	virtual void CDrawingBoard20220777View::RedrawAllToMemoryDC();


	protected:
		// 绘制辅助函数声明
		void DrawRoundedRectangle(CDC& dc, CRect rect, int cornerRadius);
		void DrawHeart(CDC& dc, CRect rect);
		void DrawStar(CDC& dc, CRect rect, int points);
		void DrawHexagram(CDC& dc, CRect rect);
		void DrawArrow(CDC& dc, CRect rect, DrawType arrowType);
		void DrawCloud(CDC& dc, CRect rect);
		void DrawWave(CDC& dc, CPoint start, CPoint end, double amplitude, double wavelength);
		void DrawWillowLeaf(CDC& dc, CRect rect);
		void DrawDiamond(CDC& dc, CRect rect);
		void DrawHexagon(CDC& dc, CRect rect);
		void DrawPentagon(CDC& dc, CRect rect);
		void Drawbomb(CDC& dc, CRect rect);

		// 形状命令处理函数声明
		afx_msg void OnShapeRoundedRect();
		afx_msg void OnShapeHeart();
		afx_msg void OnShapeStar();
		afx_msg void OnShapeHexagram();
		afx_msg void OnShapeUpArrow();
		afx_msg void OnShapeDownArrow();
		afx_msg void OnShapeLeftArrow();
		afx_msg void OnShapeRightArrow();
		afx_msg void OnShapeCloud();
		afx_msg void OnShapeWave();
		afx_msg void OnShapeWillowLeaf();
		afx_msg void OnShapeDiamond();
		afx_msg void OnShapeHexagon();
		afx_msg void OnShapePentagon();
		afx_msg void OnShapebomb();
		afx_msg void On_SDL_OnDraw();
		afx_msg void On_SDProL_OnDraw();

		void SDL_OnDraw(CDC* pDC);

		bool DL = false;
		float scale;
		int centerX, centerY, headWidth, headHeight;
		int headOffsetX;
		int headOffsetY;
		int CalculateX(int originalX);
		int CalculateY(int originalY);
		int MirrorXAbs(int originalX);
		int MirrorX(int originalX);
		void ApplyPenStyle(CDC* pDC, const LOGPEN& logPen, int cx, int cy, int a, int b, int penWidth, COLORREF transparentColor);
		void MyEllipse(CDC* pDC, int left, int top, int right, int bottom);

};

#ifndef _DEBUG  // DrawingBoard20220777View.cpp 中的调试版本
inline CDrawingBoard20220777Doc* CDrawingBoard20220777View::GetDocument() const
{
	return reinterpret_cast<CDrawingBoard20220777Doc*>(m_pDocument);
}
#endif